﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using FrameWork;
using FrameWork.Components;

namespace FrameWork.web.Module.ITMS.Service.ServResolvent
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindDataList();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataList()
        {
            QueryParam qp = new QueryParam();
            qp.Where = SearchTerms;
            qp.OrderType = 0;
            qp.PageIndex = AspNetPager1.CurrentPageIndex;
            qp.PageSize = AspNetPager1.PageSize;
            int RecordCount = 0;
            ArrayList lst = BusinessFacade.its_ResolventList(qp, out RecordCount);
            GridView1.DataSource = lst;
            GridView1.DataBind();
            this.AspNetPager1.RecordCount = RecordCount;
        }


        /// <summary>
        /// 查询条件
        /// </summary>
        private string SearchTerms
        {
            get
            {
                if (ViewState["SearchTerms"] == null)
                    ViewState["SearchTerms"] = " Where 1=1 ";
                return (string)ViewState["SearchTerms"];
            }
            set { ViewState["SearchTerms"] = value; }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            //string TroubType_Value = (string)Common.sink(TroubType.UniqueID, MethodType.Post, 10, 0, DataType.Str);
            //string ProbType_Value = (string)Common.sink(ProbType.UniqueID, MethodType.Post, 10, 0, DataType.Str);
            string Context_Value = (string)Common.sink(txtContext.UniqueID, MethodType.Post, 0, 0, DataType.Str);
            string Title_Value = (string)Common.sink(txtTitle.UniqueID, MethodType.Post, 30, 0, DataType.Str);
            StringBuilder sb = new StringBuilder();
            sb.Append(" Where 1=1 ");

            /*
            if (TroubType_Value != string.Empty)
            {
                sb.AppendFormat(" AND TroubType = {0} ", Convert.ToInt32(TroubType_Value));
            }
            
            if (ProbType_Value != string.Empty)
            {
                sb.AppendFormat(" AND ProbType = {0} ", Convert.ToInt32(ProbType_Value));
            }
            */
            if (Context_Value != string.Empty)
            {
                sb.AppendFormat(" AND Context like '%{0}%' ", Common.inSQL(Context_Value));
            }

            if (Title_Value != string.Empty)
            {
                sb.AppendFormat(" AND Title like '%{0}%' ", Common.inSQL(Title_Value));
            }
            ViewState["SearchTerms"] = sb.ToString();
            BindDataList();
            TabOptionWebControls1.SelectIndex = 0;   
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindDataList();
        }
    }
}
